<?php $this->load->view('common/admin_header');?>
<?php $this->load->view('common/kindeditor');?>
<link rel="stylesheet" type="text/css" href="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.css')?>" media="screen" />
<script type="text/javascript" src="<?=base_url('themes/admins/js/fancybox/jquery.fancybox-1.3.4.pack.js')?>"></script>
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$("#thumbnail").fancybox({
      helpers:{title:{type:'float'}}
  });
});
</script>
<div class="block withsidebar">
  <div class="block_head">
    <div class="bheadl"></div>
    <div class="bheadr"></div>
    <h2><?=$lang['global_lable_36']?></h2>
    <ul>
      <li><a href="<?=site_url('admins/pages').'?'.base64_decode($this->input->cookie('url_query'))?>"><?=$lang['global_lable_41']?></a></li>
    </ul>
  </div>
  <!-- .block_head ends -->
  <div class="block_content">
    <form id="form" name="form" action="<?=site_url('admins/pages/modify')?>" method="post" enctype="multipart/form-data">
      <input type="hidden" name="edit_id" value="<?=isset($edit_id)?$edit_id:''?>" />
      <div class="sidebar">
        <ul class="sidemenu">
          <li><a href="#sb"><?=$lang['global_lable_33']?></a></li>
          <?php foreach($languages->result_array() as $k=>$lg):?>
          <li><a href="#sb<?=$lg['id']?>"><?=$lg['name']?></a></li>
          <?php endforeach;?>
        </ul>
        <br/>
        <p>
          <input id="button1" class="btn btn-block btn-primary" type="submit" name="btn_save" value="<?=$lang['global_lable_12']?>" />
        </p>
        <p>
          <input id="button2" class="btn btn-block" type="reset" value="<?=$lang['global_lable_13']?>"/>
        </p>
      </div>
      <!-- .sidebar ends -->
      <div class="sidebar_content" id="sb">
        <?php $this->load->view('common/notify');?>
        <div class="sctitle"><i class="icon-pencil"></i> <?=$lang['global_lable_33']?></div>
      <?php $img_main_image=set_value('main_image',isset($main_image) && file_exists($main_image)?$main_image:'');?>
      <?php $show_image=!empty($img_main_image)?imagelib::resize_thumb($img_main_image,260,260):'themes/admins/img/no_image.png';?>
      <p style="display:none">
        <a id="thumbnail" href="<?=base_url().(!empty($img_main_image)?$img_main_image:'themes/admins/img/no_image.png')?>" class="thumbnail">
          <img id="img_main_image" src="<?=base_url().$show_image?>" class="preview-img" style="max-width:300px">
        </a>
      </p>
      <p style="display:none">
        <label><?=$lang['content_lable_10']?>:</label>
        <div id="simple-btn" data-tag="display_logo" class="btn btn-success js-fileapi-wrapper" style="display:none">
           <div class="js-browse">
              <input type="file" name="Filedata">
           </div>
           <div class="js-upload" style="display: none">
              <div class="progress progress-success">
                <div class="js-progress bar"></div>
              </div>
              <span class="btn-txt">Uploading (<span class="js-size"></span>)</span>
           </div>
        </div>
        <input id="old_main_image" type="hidden" name="main_image" value="<?=set_value('main_image',isset($main_image) && file_exists($main_image)?$main_image:'')?>">
        <a href="#clear_img" tag="main_image" class="btn" style="display:<?=!empty($img_main_image)?'':'none'?>"><i class="icon-trash"></i> <?=$lang['content_lable_39']?></a>
      </p>
        <p>
          <label><?=$lang['content_lable_22']?>:</label>
          <input type="text" class="text small" name="unique_url" <?=(isset($unique_url) && in_array($unique_url,array('about','contact','job')))?'readonly="readonly"':''?>  value='<?=set_value('unique_url',isset($unique_url)?$unique_url:'')?>'/>
          <span class="note required">*<?=$lang['global_lable_35']?></span>
        </p>
        <p style="display:none">
          <label><?=$lang['content_lable_28']?>:</label>
          <select name="parent" id="parent">
            <option value="0">預設類別</option>
             <?php if(isset($menus) && is_array($menus) && count($menus)>0):?>
              <?php foreach($menus as $key=>$menu):?>
              <option <?=isset($parent) && $key==$parent?'selected':''?> <?=set_select('parent',$key)?> value="<?=$key?>"><?=$menu?></option>
              <?php endforeach;?>
             <?php endif;?>
          </select>
        </p>
        <p>
          <label><?=$lang['global_lable_17']?>:</label>
          <input type="text" class="text small" name="sort_order" value='<?=set_value('sort_order',isset($sort_order)?$sort_order:0)?>'/>
        </p>
        <p>
          <label><?=$lang['global_lable_18']?>:</label>
          <input type="text" class="text Wdate small" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',lang:'zh-tw'})" name="add_time" value='<?=set_value('add_time',isset($add_time)?date($format_time,$add_time):date($format_time))?>'/>
        </p>
        <p>
          <label><?=$lang['global_lable_19']?>:</label>
          <input type="text" class="text Wdate small" onFocus="WdatePicker({dateFmt:'yyyy-MM-dd HH:mm',lang:'zh-tw'})" name="update_time" value='<?=set_value('update_time',isset($update_time)?date($format_time,$update_time):date($format_time))?>'/>
        </p>
        <p>
          <label><?=$lang['global_lable_16']?>:</label>
          <input type="radio" class="radio" name="status" value="1" <?=set_radio('status', '1', TRUE); ?> <?=isset($status) && $status==1?'checked':''?> />
          <span><?=$lang['global_lable_37']?></span>
          <input type="radio" class="radio" name="status" value="2" <?=set_radio('status', '2'); ?> <?=isset($status) && $status==2?'checked':''?> />
          <span><?=$lang['global_lable_38']?></span>
        </p>
        <p style="display:none">
          <label>完整頁面:</label>
          <input type="radio" class="radio" name="is_complete" value="1" <?=set_radio('is_complete', '1', TRUE); ?> <?=isset($is_complete) && $is_complete==1?'checked':''?> />
          <span>不是</span>
          <input type="radio" class="radio" name="is_complete" value="2" <?=set_radio('is_complete', '2'); ?> <?=isset($is_complete) && $is_complete==2?'checked':''?> />
          <span>是</span>
        </p>
        <p style="display:none">
          <label>新窗口:</label>
          <input type="radio" class="radio" name="is_new_window" value="1" <?=set_radio('is_new_window', '1', TRUE); ?> <?=isset($is_new_window) && $is_new_window==1?'checked':''?> />
          <span>不是</span>
          <input type="radio" class="radio" name="is_new_window" value="2" <?=set_radio('is_new_window', '2'); ?> <?=isset($is_new_window) && $is_new_window==2?'checked':''?> />
          <span>是</span>
        </p>
      </div>
      <?php $lang_num=$languages->num_rows();?>
      <?php foreach($languages->result_array() as $lgs):?>
      <?php $k=$lgs['id'];?>
      <div class="sidebar_content" id="sb<?=$k?>">
        <?php if($lang_num>1):?>
        <div class="sctitle"><i class="icon-pencil"></i> <?=$lgs['name']?>&nbsp;&nbsp;<a href="javascript:void(0)" class="sync_lang" lang-num="<?=$lang_num?>" lang-id="<?=$k?>" title="<?=$lang['global_lable_44']?>"><?=$lang['global_lable_45']?></a></div>
        <?php else:?>
        <div class="sctitle"><i class="icon-pencil"></i> <?=$lgs['name']?></div>
        <?php endif;?>
        <p>
          <label><?=$lang['global_lable_15']?>:</label>
          <input type="text" value="<?=set_value('descriptions['.$k.'][title]',isset($descriptions[$k]['title'])?$descriptions[$k]['title']:'')?>" class="text small" name="descriptions[<?=$k?>][title]">
          <span class="note required">*<?=$lang['global_lable_35']?></span>
        </p>
        <p>
          <label><?=$lang['content_lable_23']?>:</label>
          <textarea id="description<?=$k?>" class="details" name="descriptions[<?=$k?>][content]"><?=set_value('descriptions['.$k.'][content]',isset($descriptions[$k]['content'])?$descriptions[$k]['content']:'')?>
</textarea></p>
      </div>
      <?php endforeach;?>
    </form>
  </div>
  <!-- .block_content ends -->
  <div class="bendl"></div>
  <div class="bendr"></div>
</div>
<!-- .block ends -->
<script type="text/javascript" charset="utf-8">
window.FileAPI = {
  debug: true, // debug mode
  cors: false,    // if used CORS, set `true`
  flashUrl:"<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.flash.swf')?>",
  staticPath:'themes/admins/js/jquery.fileapi/FileAPI/' // path to *.swf
};
</script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.min.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/FileAPI/FileAPI.exif.js')?>"></script>
<script src="<?=base_url('themes/admins/js/jquery.fileapi/jquery.fileapi.js')?>"></script>
<script type="text/javascript" charset="utf-8">
  $(document).ready(function($) {
    var folder=encodeURIComponent('uploads/pages/');
    $('#simple-btn').fileapi({
       url:"<?=site_url('admins/upload/single_upload')?>",
       data: {'folder':folder,'_size':'260x260','_element_id':'main_image','_admin_id':"<?=$this->nsession->userdata('admin_id')?>",'_nickName':"<?=$this->nsession->userdata('nick_name')?>"},
       multiple: false,
       accept: 'image/*',
       maxSize: 2 * FileAPI.MB,
       autoUpload: true,
       clearOnComplete:true,
       elements: {
          size: '.js-size',
          active: { show: '.js-upload', hide: '.js-browse' },
          progress: '.js-progress'
       },
       onComplete:function(evt,uiEvt){
        var error = uiEvt.error;
        var result = uiEvt.result; // server response
        if(!error && result){
          // console.log(result);
          if(result.error){
            alert(result.error);
            return;
          }
          $("#old_"+result.element_id).val(result.img_path);
          $("#img_"+result.element_id).attr('src',result.thumb_img);
          if ($('#thumbnail').length)
            $("#thumbnail").attr('href',result.http_img);
          if ($('a[href="#clear_img"]').length)
            $('a[href="#clear_img"]').show();
        }
      }
    });
    //清除圖片
    $('a[href="#clear_img"]').click(function() {
      var obj=$(this);
      var action="<?=site_url('admins/upload/delete')?>";
      var defaule_img="<?=base_url('themes/admins/img/no_image.png')?>";
      clear_img(obj,action,defaule_img);
      return false;
    });
  });
</script>
<?php $this->load->view('common/admin_footer');?>
